package demo2;

public class Test {
    public static void main(String[] args) {
        String str1 = new String("careathers");
        String str2 = new String("careathers");
        System.out.println(str1.equals(str2));
    }
    public static void main1(String[] args) {
        Object o = new Object();
        Object o1 = o;
        Object o2 = o;
        System.out.println(o1.equals(o2));
    }
}
class Animal{
    public String name;
    public Animal(String name) {
        this.name = name;
    }
    //String类中已重写equals方法
    public boolean equals(Animal o) {
        if(this==o) {
            return true;
        }
        if(o==null) {
            return false;
        }
        return this.name.equals(o.name);
    }
    public static void main(String[] args) {
        Animal cat1 = new Animal("花花");
        Animal cat2 = new Animal("花花");
        System.out.println(cat1.equals(cat2));
        System.out.println(cat1==cat2);
    }
}
